package com.softline.documentsmall.service.impl;

import com.softline.documentsmall.dao.RandomDictionaryMapper;
import com.softline.documentsmall.entity.RandomDictionary;
import com.softline.documentsmall.entity.RandomDictionaryVO;
import com.softline.documentsmall.exception.CustomException;
import com.softline.documentsmall.exception.GlobalException;
import com.softline.documentsmall.service.RandomDictionaryService;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: documentsmall
 * @description: 随机词条service
 * @author: wmj
 * @create: 2020-12-07
 * @ClassName: RandomDictionaryServiceImpl
 */

@Service
@Slf4j
public class RandomDictionaryServiceImpl implements RandomDictionaryService {

    @Autowired
    RandomDictionaryMapper randomDictionaryMapper;

    @Override
    public List<RandomDictionaryVO> listByLanguage(String type) {
        List<RandomDictionaryVO> randomDictionaryVOS = randomDictionaryMapper.listByLanguage(type);
        return randomDictionaryVOS;
    }

    @Override
    public int add(RandomDictionary randomDictionary) {
        RandomDictionary dictionary = randomDictionaryMapper.select(randomDictionary.getDictionaryId());
        int result = 0;
        if(dictionary!=null){
            return result;
        }else {
            int insert = randomDictionaryMapper.insert(randomDictionary);
            return  insert;
        }
    }

    @Override
    public void delete(Integer id) {
        randomDictionaryMapper.deleteByPrimaryKey(id);
    }
}
